<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="../style/journal.css" type="text/css" />
<style type="text/css"><!--
.googleadsense {
	margin: 2px;
	padding: 0px;
//--></style><script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-65008-1";
urchinTracker();
</script><title>Javascript: Events</title>
</head>
<body>
<a href="index.html">Journal</a>(2005) | <a href="../blog/"><b>Blog</b></a>(2006) | <a href="http://www.fayland.org/cgi-bin/random_link.pl">RandomLink</a> | <a href="AboutFayland.html">WhoAmI</a> | <a href="LiveBookmark.html">LiveBookmark</a> | <a href="http://www.fayland.org/">HomePage</a>
<p><&lt;Previous: <a href="050510.html">Day [05.5.10] China.pm.org</a>&nbsp;&nbsp;>>Next: <a href="split.html">split</a></p>
<h1>Javascript: Events</h1>
<div class='content'>
<p>Category: <a href='Javascript.html'>Javascript</a> &nbsp; Keywords: <b>Javascript Events Ctrl+Enter</b></p><h2>问题</h2>
用过 <a href='http://www.qq.com'>QQ</a> 的人都熟悉用 Ctrl+Enter 来发送信息。<br>
网上大部分论坛程序都支持用 Ctrl+Enter 发表帖子，不过当我使用 Firefox 时，大部分论坛（我知道的都不成）这个功能都实效了。<br>
跟 Joe 在 IRC 里说起 Gmail 的 hotkey, 发现在 Firefox 里也是可以使用的。不过找不到 Gmail 的源代码，还好可以用 <a href='http://www.google.com'>Google</a><br>

<h2>解决方案</h2>
<pre><code>
&lt;script type="text/javascript">
var x,q;

function ctlent(e){
  if (document.all){
    x = window.event.keyCode;
    q = event.ctrlKey;
  } else {
    x = e.keyCode;
    q = e.ctrlKey;
  }
  if (q && x==13) {
    this.document.FORM.submit();
    this.document.FORM.Submit.disabled = true;
  }
  if (!document.all){
       window.captureEvents(Event.KEYPRESS);
       window.onkeypress = ctlent;
  }else{
       document.onkeypress = ctlent;
  }
}

function submitonce(form){
    for (var i=0;i&lt;form.elements.length;i++) {
        var e=form.elements[i];
        if(e.type.toLowerCase()=="submit") e.disabled=true;
    }
}
&lt;/script>
&lt;form name="FORM" onSubmit="submitonce(this)">
&lt;textarea cols=75 name=inpost onKeyDown="ctlent(event)" rows=7>&lt;/textarea>
&lt;INPUT name="Submit" type=submit>
&lt;/form>
</code></pre>

<h2>Refer</h2>
<ul>
<li><a href='http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21382788.html'>http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21382788.html</a>
</ul></div>
<p><&lt;Previous: <a href="050510.html">Day [05.5.10] China.pm.org</a>&nbsp;&nbsp;>>Next: <a href="split.html">split</a></p>
<p><strong>Options:</strong> <a href='http://del.icio.us/post?title=Javascript:%20Events&url=http://www.fayland.org/journal/JS_event.html'>+Del.icio.us</a></p>
<strong>Related items</strong>
<ul><li><a href='JS_encode.html'>Ajax && encodeURIComponent</a> < <span class='digit'>2005-05-15 15:31:00</span> ></li><li><a href='AutoSave.html'>AutoSave / 自动存储</a> < <span class='digit'>2005-10-14 01:26:10</span> ></li></ul>
Created on <span class="digit">2005-05-10 23:36:36</span>, Last modified on <span class="digit">2005-10-14 01:00:59</span><br />
Copyright 2004-2005 All Rights Reserved. Powered by <a href="Eplanet.html">Eplanet</a> && <a href='http://catalyst.perl.org'>Catalyst</a> 5.62.
</body>
</html>